/*
 * @Author: zhujunzhujunzhu 2693474327@qq.com
 * @Date: 2022-11-26 17:58:25
 * @LastEditors: zhujunzhujunzhu 2693474327@qq.com
 * @LastEditTime: 2022-11-26 18:07:38
 * @FilePath: \web-gl-learn\canvas\ball.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
function Ball(x,y,raduis,color,scaleX,scaleY){
    // 小球中心点位置 
    this.x = x||0
    this.y = y||0 
    // 小球半径
    this.raduis = raduis||12
    // 小球颜色
    this.color = color|| "#6699FF"

    // 缩放值
    this.scaleX = scaleX || 1
    this.scaleY = scaleY|| 1

    
}

Ball.prototype = {
    // 绘制描边的小球
    stroke:function(cxt){
        cxt.save() // 保存上一个状态
        cxt.scale(this.scaleX,this.scaleY) // 处理缩放
        cxt.strokeStyle = this.color
        cxt.beginPath();
        cxt.arc(this.x,this.y,this.raduis,0,360*Math.PI/180,false)
        cxt.closePath()
        cxt.stroke()
        cxt.restore()
    },

    // 绘制填充的小球
    fill:function(cxt){
        cxt.save()
        cxt.translate(this.x,this.y)
        cxt.rotate(this.rotation)
        cxt.scale(this.scaleX,this.scaleY) // 处理缩放
        cxt.fillStyle = this.color
        cxt.beginPath();
        cxt.arc(0,0,this.raduis,0,360*Math.PI/180,false)
        cxt.closePath()
        cxt.fill()


        cxt.restore()

    },
    image:function (cxt,img){
        cxt.save()
        cxt.translate(this.x,this.y)
        cxt.rotate(this.rotation)
        // cxt.scale(2,2)
        cxt.scale(this.scaleX,this.scaleY) // 处理缩放
        cxt.strokeStyle = this.color
        cxt.beginPath();
        // cxt.arc(0,0,this.raduis,0,360*Math.PI/180,false)
        cxt.arc(0,0,20,0,360*Math.PI/180,false)
        // cxt.stroke()
        cxt.closePath()
        cxt.clip()
       
        // cxt.drawImage(img,-40,-40,80,80)
        cxt.drawImage(img,-20,-20,40,40)
        cxt.restore()
    }
}